package com.ych.modules.api.authorInfc.user.controller;

import com.baomidou.mybatisplus.plugins.Page;
import com.ych.modules.api.authorInfc.user.entity.AddFeedbackEntity;
import com.ych.modules.base.dbEntity.TUserFeedbackEntity;
import com.ych.modules.common.entity.query.QueryUserFeedbackEntity;
import com.ych.modules.common.service.UserFeedbackService;
import com.ych.utils.TLMap;
import com.ych.utils.mysqlPageUtil.PageUtils;
import com.ych.utils.serviceReturn.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created with IntelliJ IDEA.
 * Author: Usopp.tsui
 * Date: 2021/1/2
 * Time: 12:21
 * Description:
 */
@RestController("apiUserFeedbackController")
@RequestMapping("/api/auth/user/feedback")
@Api(tags = {"API——用户反馈"}, description = "API——用户反馈")
public class UserFeedbackController {
    @Autowired
    private UserFeedbackService userFeedbackService;

    @PostMapping("/listFeedback")
    @ApiOperation(value = "查询反馈列表", notes = "查询反馈列表")
    public R<Page<TUserFeedbackEntity>> listFeedback() {
        try {
            QueryUserFeedbackEntity entity = new QueryUserFeedbackEntity();
            entity.setUserId(TLMap.getUserId());
            Page<TUserFeedbackEntity> page = userFeedbackService.listUserFeedback(entity);
            return new R(0, "成功", new PageUtils(page));
        } catch (Exception e) {
            return new R(1, e.getMessage(), null);
        }
    }

    @PostMapping("/addFeedback")
    @ApiOperation(value = "添加反馈信息", notes = "添加反馈信息")
    public R<String> addFeedback(@RequestBody AddFeedbackEntity entity) {
        try {
            TUserFeedbackEntity feedbackEntity = new TUserFeedbackEntity();
            feedbackEntity.setFeedbackType(entity.getFeedbackType());
            feedbackEntity.setUrlList(String.join(",",entity.getUrlList()));
            feedbackEntity.setContent(entity.getContent());
            feedbackEntity.setUserId(TLMap.getUserId());
            userFeedbackService.addFeedback(feedbackEntity);
            return new R(0, "成功", null);
        } catch (Exception e) {
            return new R(1, e.getMessage(), null);
        }
    }
}
